package com.example.stray_animal_management_system.commonu.controller;

import com.example.stray_animal_management_system.admin.service.VolunteerApplicationService;
import com.example.stray_animal_management_system.entity.Volunteer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: panpan
 * @time: 2025/11/8
 */
@RestController
@RequestMapping("/api/user/volunteer")
public class VolunteerApplicationController {

    @Autowired
    private VolunteerApplicationService volunteerApplicationService;

    /**
     * 用户申请成为志愿者
     */
    @PostMapping("/apply")
    public Map<String, Object> applyVolunteer(@RequestBody Volunteer application) {
        Map<String, Object> res = new HashMap<>();

        // 获取当前用户ID
        Integer userId = application.getUserId();

        // 设置申请状态为待审核（0）
        application.setStatus(0);  // 0表示待审核
        volunteerApplicationService.save(application);

        res.put("code", 200);
        res.put("msg", "申请已提交，请等待审核");
        return res;
    }
}
